<template>
  <el-dialog
    v-bind="$attrs"
    :close-on-click-modal="false"
    :modal-append-to-body="false"
    v-on="$listeners"
    @open="onOpen"
    fullscreen
    lock-scroll
    class="jsbos-full-dialog"
    append-to-body
    :show-close="false"
    :modal="false"
  >
    <div class="jsbos-full-dialog-header">
      <div class="header-title">
        <p class="header-txt">{{ title }}</p>
      </div>
      <div class="options">
        <el-form>
          <el-button @click="goBack()" :disabled="false">{{
            $t("common.cancelButton")
          }}</el-button>
        </el-form>
      </div>
    </div>
    <div class="main">
      <div class="content">
        <iframe width="100%" height="100%" :src="url" frameborder="0"></iframe>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { PreviewFile } from "@/api/common";
export default {
  props: ["file"],
  data() {
    return {
      title: "",
      url: "",
    };
  },
  methods: {
    goBack() {
      this.$emit("update:visible", false);
      // this.$emit('')
      if (this.$route.query.contract_id) {
        this.$router.push({
          path: this.$route.path,
          query: {
            applicationId: this.$route.query.applicationId,
          },
        });
      }
      console.log(this.$route);
    },
    onOpen() {
      this.title = "文档预览 - " + this.file.name;
      this.url = "";
      let query = {
        fileName: this.file.fileId,
        fileVersionId: this.file.fileVersionId,
        fileDownloadUrl: this.file.url,
        secondFilePath: this.file.secondFilePath,
      };
      console.log("PreviewFile====>", query);
      PreviewFile(query).then((res) => {
        if (res.data) {
          this.url = res.data;
        } else {
          this.$message.warning("文件不存在");
          this.goBack();
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.content {
  width: 100%;
  height: 100%;
  background: #fff;
}
</style>
